package com.yanqu.road.server.cross3server.cmd.activity.entername;

import com.yanqu.road.entity.activity.entername.UserEnterName;
import com.yanqu.road.logic.activity.entername.ChannelEnterNameHelper;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.cross3server.manager.Cross3EnterNameMgr;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Cross3Protocol.C3_ENTER_NAME_ADD_FROM_CHANNEL, desc = "玩家自主报名返回")
public class Cross3EnterNameAddFromChannelCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        EnterNameProto.EnterNameAddRespMsg respMsg = EnterNameProto.EnterNameAddRespMsg.parseFrom(yanQuMessage.getBytes());
        //缓存本渠道的报名数据
        UserEnterName userEnterName = ChannelEnterNameHelper.parseFromMsg(respMsg.getEnterName());
        Cross3EnterNameMgr.add(userEnterName);

        MessageHelper.sendPacket(respMsg.getEnterName().getServerId(), respMsg.getEnterName().getUserId(),
                YanQuMessageUtils.buildMessage(Protocol.U_ENTER_NAME_ADD, respMsg.toBuilder()));

    }
}
